import MainHomePageUI = layaUI.main.MainHomePageUI;
import HomePage = data.HomePage;


class MainHomePage extends MainHomePageUI{
    private AniConfPath1: string = "res/atlas/10002.atlas";
    private ani1: Animation;

    private AniConfPath2: string = "res/atlas/10003.atlas";
    private ani2: Animation;

    constructor(){
        super();
        //添加侦听
        this.btnStart.on(Laya.Event.CLICK,this,this.onStart);
        this.content2.on(Laya.Event.LINK,this,this.linkHandler);
        //title
        this.title1.style.align = "center";
        this.title2.style.align = "center";
        this.content3.style.align = "center";
        //内容
        this.content1.style.wordWrap = true;
        this.content1.style.leading = 20;
        this.content2.style.wordWrap = true;
        this.content2.style.leading = 20;
        //设置内容
        this.title1.innerHTML = LangUtils.getText(1);
        this.title2.innerHTML = LangUtils.getText(2);
        this.content1.innerHTML = LangUtils.getText(15);
        this.content2.innerHTML = LangUtils.getText(16);
        this.content3.innerHTML = LangUtils.getText(34);
        //布局
        this.content1.y = this.title1.y + this.title1.contextHeight;
        this.title2.y = this.content1.y + this.content1.contextHeight;
        this.content2.y = this.title2.y + this.title2.contextHeight;
        //加载特效
        this.AniConfPath1 = Global.LANGUAGE == LanguageType.CHINESE ? "res/atlas/10002.atlas" : "res/atlas/10004.atlas";
        Laya.loader.load(
            [
                {url:this.AniConfPath1,type:Loader.ATLAS},
                {url:this.AniConfPath2,type:Loader.ATLAS}
            ], Handler.create(this,this.onLoaded)
        );
        this.ani1 = new Animation();
        this.ani2 = new Animation();
        //语言包
        LangUtils.setSkin(this.btnStart);
        LangUtils.setSkin(this.img1);
        LangUtils.setSkin(this.img2);
        LangUtils.setSkin(this.img3);
        LangUtils.setSkin(this.img4);
        LangUtils.setSkin(this.img5);
        LangUtils.setSkin(this.img6);
        LangUtils.setSkin(this.img7);
        //cdn加载
        ResUtils.setLoadSkin(this.imgBig1);
        ResUtils.setLoadSkin(this.imgBig2);
        ResUtils.setLoadSkin(this.imgBig3);
        ResUtils.setLoadSkin(this.imgBig4);
        ResUtils.setLoadSkin(this.imgBig5);
        ResUtils.setLoadSkin(this.imgBig6);
    }

    /**
     * 添加侦听
     */
    public addEvent():void{
        //播放特效
        this.onLoaded();
    }

    /**
     * 移除侦听
     */
    public removeEvent():void{
        this.ani1.stop();
        this.ani2.stop();
    }

    //特效加载完成
    private onLoaded():void{
        this.ani1.loadAtlas(this.AniConfPath1); // 加载图集动画
        this.ani1.interval = 150; // 设置播放间隔（单位：毫秒）
        this.ani1.index = 1; // 当前播放索引
        this.ani1.play(); // 播放图集动画
        // 获取动画的边界信息
        var bounds1: Rectangle = this.ani1.getGraphicBounds();
        this.ani1.pivot(bounds1.width / 2, bounds1.height / 2);
        this.ani1.pos(this.width / 2, 150);
        this.addChild(this.ani1);
        this.ani2.loadAtlas(this.AniConfPath2); // 加载图集动画
        this.ani2.interval = 150; // 设置播放间隔（单位：毫秒）
        this.ani2.index = 1; // 当前播放索引
        this.ani2.play(); // 播放图集动画
        // 获取动画的边界信息
        this.ani2.pos(0,-40);
        this.aniSpr.addChild(this.ani2);
    }

    //点击开始
    private onStart():void{
        MainView.getInstance().setTabSelectIndex(1);
    }

    //连接点击
    private linkHandler(url:string):void{
        window.open(url);
    }
}